package com.eagle.view.fragment.meeting;

import android.text.TextUtils;

import com.eagle.EApplication;
import com.eagle.R;
import com.eagle.support.constants.Constants;
import com.eagle.support.helper.CallHelper;
import com.eagle.support.utils.SoftInputKeyboardUtils;
import com.eagle.support.utils.ToastUtils;
import com.eagle.view.activity.MeetingActivity;
import com.eagle.view.fragment.live.BaseFragment;
import com.eagle.view.widget.base.EEditView;
import com.kinstalk.voip.sdk.EngineSdkCallMode;
import com.kinstalk.voip.sdk.EngineSdkUserRole;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.EditorAction;
import org.androidannotations.annotations.ViewById;

/**
 * Created by gc on 2017/1/13.
 */
@EFragment(R.layout.fragment_meeting_operation)
public class FragmentMeetingOperation extends BaseFragment {

    @ViewById(R.id.et_room)
    protected EEditView mEtRoomId;

    @ViewById(R.id.et_invitation)
    protected EEditView mEtInvitation;

    protected String mLoginUid;

    private CallHelper mCallHelper;

    private MeetingActivity mActivity;

    private boolean mCreateMeeting;

    @AfterViews
    void initView() {
        mActivity = (MeetingActivity) getActivity();
        mCallHelper = mActivity.getCallHelper();
        mCallHelper.userRole(EngineSdkUserRole.ES_UR_TYPE_SLAVER.swigValue());
        mLoginUid = EApplication.getSharedPreferences().getString(Constants.LOGIN_UID, "");
        mCallHelper.uid(mLoginUid).callMode(EngineSdkCallMode.ES_CM_TYPE_CONFERENCE_CLIENT.swigValue());
    }

    @Click(R.id.btn_create)
    void onCreate() {
        String invitation = mEtInvitation.getText().toString();
        if (!TextUtils.isEmpty(invitation)) {
            mCreateMeeting = false;
            showLoading();
            SoftInputKeyboardUtils.hideSoftInput(mEtInvitation);
            mCallHelper.createMeeting(invitation, false);
        } else {
            ToastUtils.showToast(mActivity, "invite id can't be null", R.id.layout_parent);
        }
    }

    @EditorAction(R.id.et_invitation)
    void onInvitation() {
        onCreate();
    }

    @Click(R.id.btn_join)
    void onJoin() {
//        String roomId = mEtRoomId.getText().toString();
//        if (!TextUtils.isEmpty(roomId)) {
//            mCreateMeeting = true;
//            showLoading();
//            SoftInputKeyboardUtils.hideSoftInput(mEtRoomId);
//            mCallHelper.joinMeeting(roomId);
//        } else {
        ToastUtils.showToast(mActivity, "Waiting for development.", R.id.layout_parent);
//        }
    }

    public boolean isCreateMeeting() {
        return mCreateMeeting;
    }
}
